import java.util.ArrayList;
import java.awt.Graphics;
public class Answers implements Drawable
{
    ArrayList<Card> myHand = new ArrayList<Card>();
    private Board b;
    private Vec2 start = new Vec2(250,150);
    private int gap = 15;
    Answers(Board b){
        this.b =b;
    }
    public boolean insert(Board b, String s){
        if(isFull())return false;
        
        SelectionAction SA = new SelectionAction(b);
        Card c = new Card(100,100,b,SA, false, s);
        SA.setButton(c);
        myHand.add(c);
        
        c.adHeight(-110);
        c.adWidth(-20);
        b.myButtons.add(c);
       
        return true;
    }
    public void paint(Graphics g){
        for(int i = 0; i < myHand.size(); i++){
            Vec2 pos = new Vec2(start.X, start.Y + (myHand.get(i).getHeight() + gap)*i);
            myHand.get(i).getPhy().setPosition(pos);
            myHand.get(i).paint(g);
        }
    }
    
    public int getNumberSeleceted(){
        int anzahl = 0;
        for(int i = 0 ; i < myHand.size(); i++)
        {
            if(myHand.get(i).selected)
            anzahl ++;
        }
        return anzahl;
    }
    
    public boolean isFull(){
        return myHand.size() == 6;
    }
    public void add(){
        myHand.get(1).backUpFont = myHand.get(1).backUpFont.deriveFont(myHand.get(1).backUpFont.getSize()+1f);
    }
    
    public boolean canSelect(Card c){
        if(getNummer(c)==-1)
            return false;
        if(c.selected){
            return true;
        }
        int  count = 0;
        for(int i = 0; i < myHand.size(); i++){
            if(myHand.get(i).selected) count++;
        }
        if(count >= 1)
            return false;
        return true;
    }
    public Card getSelected(){
        for(int i = 0; i < myHand.size(); i++){
            if(myHand.get(i).selected) return myHand.get(i);
        }
        return null;
    }
    public Card getCardWith(String starting){
        for(int i = 0; i < myHand.size(); i++){
            if(myHand.get(i).getText().startsWith(starting))return myHand.get(i);
        }
        return null;
    }
    public int getNummer(Card c){
        for(int i = 0; i<myHand.size(); i++){
            if(myHand.get(i).getText().equals( c.getText()))return i;
        }
        return -1;
    }
}
